package com.example.java_chatroom.service;

import com.example.java_chatroom.mapper.FriendInfoMapper;
import com.example.java_chatroom.model.FriendInfo;
import com.example.java_chatroom.model.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FriendInfoService {
    @Autowired
    private FriendInfoMapper friendInfoMapper;

    public List<FriendInfo> getFriendList(Integer userId) {
        return friendInfoMapper.selectFriendList(userId);
    }

    public void insertfriend(Integer userId, Integer userId1) {
        friendInfoMapper.insertFriend(userId, userId1);
        friendInfoMapper.insertFriend(userId1, userId);
    }

    public FriendInfo getFriend(String friendName) {
        return friendInfoMapper.getFriend(friendName);
    }

    public List<FriendInfo> getOtherFriendList(UserInfo userInfo, List<FriendInfo> friendInfos) {
        return friendInfoMapper.getOtherFriendList(userInfo, friendInfos);
    }

    public List<FriendInfo> getGroupList(Integer sessionId) {
        return friendInfoMapper.getGroupList(sessionId);
    }

    public void deleteFriendByUserId(Integer userId) {
        //双向
        friendInfoMapper.deleteFriendByUserId(userId);
        friendInfoMapper.deleteFriend1ByUserId(userId);
    }

    public void deleteFriendByUserIdAndfriendId(Integer friendId, Integer userId) {
        friendInfoMapper.deleteFriendByUserIdAndfriendId(friendId, userId);
        friendInfoMapper.deleteFriendByUserIdAndfriendId(userId, friendId);

    }

    public Integer queryFriendByFriendAndUserId(Integer friendId, Integer userId) {
        return friendInfoMapper.queryFriendByFriendAndUserId(friendId, userId);
    }
}
